package what.basic.collection;

import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Set;
import java.util.WeakHashMap;

public class hashmap {
	public static void main(String[] args) {
		student[] stu=new student[10];
		student stud;
		stu[2]=new student(1,"a","b");
		stu[1]=new student(2,"c","d");
		stu[0]=new student(3,"e","f");
		HashMap<Integer,student> map=new HashMap<Integer,student>();
		map.put(stu[0].getstudentid(), stu[0]);
		map.put(stu[1].getstudentid(), stu[1]);
		map.put(stu[2].getstudentid(), stu[2]);
		stud=map.get(2);
		Set<Integer> keys=map.keySet();
		System.out.println("Set<Integer> keys=map.keySet();");
		for(Integer i:keys){
			stud=map.get(i);
			System.out.println("key:"+i+"  value:"+stud.getfullname());
		}
		System.out.println("IdentityHashMap<Integer,student> map1=new IdentityHashMap<Integer,student>();");
		IdentityHashMap<Integer,student> map1=new IdentityHashMap<Integer,student>();
		map1.put(stu[0].getstudentid(), stu[0]);
		map1.put(stu[0].getstudentid(), stu[0]);
		map1.put(stu[0].getstudentid(), stu[0]);
		map1.put(stu[1].getstudentid(), stu[1]);
		for(student s:map1.values())
			System.out.println(s.getstudentid()+s.getfullname());
		for(Integer i: map1.keySet())
			System.out.println(i);
		WeakHashMap<Integer,student> map2=new WeakHashMap<Integer,student>();
		System.out.println("WeakHashMap<Integer,student> map2=new WeakHashMap<Integer,student>();");
		map2.put(stu[0].getstudentid(), stu[0]);
		map2.put(stu[1].getstudentid(), stu[1]);
		map2.put(stu[2].getstudentid(), stu[2]);
		for(student s:map2.values())
			System.out.println(s.getstudentid()+s.getfullname());
		System.out.println("The map initially contained:"+map2.size()+" entries");
		System.gc();
		System.out.println("The map now contained:"+map2.size()+" entries");
		
	}

}
